package com.example.project1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    TextView textView;
    EditText user;
    EditText pwd;
    CheckBox checked;
    Button button;
    TextView hint;

    public static final String MSG_TYPE = "AAA";
    public static final String isCheck = "checked";
    public static final String USER = "admin";
    public static final String PWD = "123456";
    String msg = "";
    boolean f = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textView = findViewById(R.id.ceiling);
        user = findViewById(R.id.Username);
        pwd = findViewById(R.id.password);
        checked = findViewById(R.id.check);
        button = findViewById(R.id.btn);
        hint = findViewById(R.id.Wrong_MSG);

        checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                f = b;
            }
        });
    }

    public void Submit(View view) {
        if (!f || (f && (user.getText().toString().equals(USER))) && (pwd.getText().toString().equals(PWD))) {
            msg += "User: " + user.getText().toString() + "\n";
            msg += "Password: " + pwd.getText().toString() + "\n";
            msg += (f ? isCheck : "");
            Intent intent = new Intent(this,JumpToPage.class);
            intent.putExtra(MSG_TYPE,msg);
            startActivity(intent);
        } else {
            hint.setVisibility(View.VISIBLE);
        }
        user.setText("");
        pwd.setText("");
        msg = "";
    }
}